Skip to content

Move thread-local connections from examples to recipes#104

Open
MeanSquaredError wants to merge 3 commits intorbock:mainfrom
MeanSquaredError:thread_local_connection
Open

Move thread-local connections from examples to recipes#104
MeanSquaredError wants to merge 3 commits intorbock:mainfrom
MeanSquaredError:thread_local_connection

Conversation

@MeanSquaredError
Copy link
Contributor

As discussed here, this PR moves thread-local connections from examples to recipes and documents the pattern.

Copy link
Owner

@rbock rbock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

LGTM except for a couple of nits.

We define a database connection class called `lazy_connection`, which mimics the regular database connections provided by sqlpp23 and lets the user execute database queries, pretty much like a regular sqlpp connection does. In fact, our lazy connection creates an underlying sqlpp database connection and forwards all database queries to the sqlpp connection, but that sqlpp connection is not
created immediately in the constructor of the lazy connection. Instead, its creation is postponed until the moment when the user tries to execute their first query through our lazy connection object, which is why our connection class is called "lazy".

There is only one, global instance of our `lazy_connection` class, called `g_dbc`, which is defined as
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence seems odd.

In a multi-threaded program, there are multiple instances, because it is not global but thread-local.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that sentence was not worded very well. Changed it to

Database queries are made through a global object called g_dbc, which is defined as

Does that make more sense?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. Thanks for asking. What's global is the name, but not any object (they are thread-local).

We could say that we create a thread-local variable of typelazy_connection called g_dbc at global scope.

@MeanSquaredError
Copy link
Contributor Author

OK, I (hopefully) fixed the issues that you found and also moved some of the text into an initial paragraph, summarizing the purpose of the document.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants